package com.j2009.springbootproject.web;

import com.j2009.springbootproject.entity.User;
import com.j2009.springbootproject.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ClassName: RedisTestController
 * Description:
 * date: 2021/3/31 12:18
 *
 * @author wuyafeng
 * @version 1.0   softeem.com
 */
@Controller
@Slf4j
public class RedisTestController {

    @Autowired
    private RedisUtil redisUtil;

    @ResponseBody
    @RequestMapping("/test")
    public String test(){
        //存储数据到redis中
        redisUtil.set("redisTest","这是一条测试数据",0);
       String info = (String) redisUtil.get("redisTest",0);
         log.info("redis存储成功");
         return "成功"+info;
    }


    @ResponseBody
    @RequestMapping("/testUser")
    public User testUser(){
        User user = new User(1002,"张三","123456");
        redisUtil.set("user",user,0);
        User user1 = (User) redisUtil.get("user",0);
        return user1;
    }

}
